﻿<UserControl
    x:Class="DvachBrowser3.Views.Partial.PostCollectionView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DvachBrowser3.Views.Partial"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:vm="using:DvachBrowser3.ViewModels"
    xmlns:int="using:Microsoft.Xaml.Interactivity"
    xmlns:behaviors="using:DvachBrowser3.Behaviors"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    x:Name="ThisControl">

    <Grid>
        <ListView x:Name="MainList" ItemsSource="{x:Bind ViewModel.Posts, Mode=OneWay}" SelectionMode="None" Header="{x:Bind Header, Mode=OneWay}" Footer="{x:Bind Footer, Mode=OneWay}">
            <ListView.ItemContainerTransitions>
                <TransitionCollection />
            </ListView.ItemContainerTransitions>
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="Padding" Value="0" />
                    <Setter Property="Template" Value="{StaticResource CleanListItem}" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="vm:IPostViewModel">
                    <local:PostView ViewModel="{x:Bind}" MaxLines="{Binding ElementName=ThisControl, Path=MaxLines, Mode=OneWay}"
                                    ShowCounter="{Binding ElementName=ThisControl, Path=ShowCounter, Mode=OneWay}" 
                                    ShowPreviewSeparator="{Binding ElementName=ThisControl, Path=ShowPreviewSeparator, Mode=OneWay}"
                                    ShowFullThreadText="{Binding ElementName=ThisControl, Path=ShowFullThreadText, Mode=OneWay}"
                                    ShowFullPostButton="{Binding ElementName=ThisControl, Path=ShowFullPostButton, Mode=OneWay}"
                                    ShowFullThread="PostView_OnShowFullThread" ShowFullPost="PostView_OnShowFullPost">
                        <int:Interaction.Behaviors>
                            <behaviors:PopupMenuBehavior>
                                <behaviors:PopupMenuBehavior.MenuFlyout>
                                    <MenuFlyout>
                                        <MenuFlyoutItem Text="Копировать текст" Tag="{x:Bind}" Click="CopyTextFlyoutItem_OnClick"/>
                                        <MenuFlyoutItem Text="Копировать ссылку" Tag="{x:Bind}" Click="CopyLinkFlyoutItem_OnClick" />
                                        <MenuFlyoutItem Text="Во весь экран" Tag="{x:Bind}" Click="ShowFullScreenFlyoutItem_OnClick"
                                                        Visibility="{Binding ElementName=ThisControl, Path=ShowFullPostButton, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=false}"/>
                                        <MenuFlyoutItem Text="Ответить" Tag="{x:Bind}" Click="PostQuoteFlyoutItem_OnClick"/>
                                    </MenuFlyout>
                                </behaviors:PopupMenuBehavior.MenuFlyout>
                            </behaviors:PopupMenuBehavior>
                        </int:Interaction.Behaviors>
                    </local:PostView>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>
